package org.kaindorf.kainflix.metadata.controller.advice;

import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 *
 * @author Thomas
 */
@ControllerAdvice
public class GlobalControllerAdvice {
    
    @ExceptionHandler(NoHandlerFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ModelAndView handleRequestWithoutMapping(NoHandlerFoundException ex){
        ModelAndView modelAndView = new ModelAndView("pageNotFound");
        modelAndView.addObject("requestedUrl", ex.getRequestURL());
        return modelAndView;
    }
    
//    @ExceptionHandler(Exception.class)
////    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    @ResponseBody
//    public String handleRequestWithoutMapping(Exception ex){
//        return "Sorry, something went wrong. Bye.";
//    }
}
